<template>
  <div class="page-container">
    <van-row>
      <van-col span="24">
        <FortenScan
          ref="scanDom"
          propPlaceholder="请扫描调拨单号"
          propErrorMsg="请扫描正确的调拨单号"
          :propTypeArr="['wm_transfer_bus_key']"
          @scanCall="handleScanOver"
          @btnClick="handleGoTo"
          :showBtn="true"
        >
        <template slot="btn">
          <van-icon name="plus"/>
        </template>
        </FortenScan>
      </van-col>
    </van-row>
    <van-form >
    <div class="items-container">
      <FortenCollapse   ref="fsList" @call="fsCall"
        clickTo="editTransferPick"
        titleWarningField="applyQty"
        titleWarningText="申请单品"

        titleSuccessField="pickQty"
        titleSuccessText="已拣单品"

        titleTextField="toWarehouseName"
        titleText="收货仓库"

        groupValueField="toWarehouseId"
        groupTextField="toWarehouseName"
        groupText="收货仓库"
        pkName="id"
        :keepActive="true"
      >
        <template #default="{item}">
            <van-row>
              <van-col span="12"><van-icon name="clock-o" size="15" color="#1989fa" style="top: 3px;"/> 创建时间</van-col>
              <van-col span="12"><van-icon name="label-o" size="15" color="#1989fa" style="top: 3px;"/> 调拨单号</van-col>
            </van-row>
            <van-row>
              <van-col span="12" class="list-value">{{item.gmtCreate}}</van-col>
              <van-col span="12" class="list-value">{{item.busKey}}</van-col>
            </van-row>
            <van-row>
              <van-col span="12"><van-icon name="cart-o" size="15" color="#1989fa" style="top: 3px;"/> 配送仓库</van-col>
              <van-col span="12"><van-icon name="orders-o" size="15" color="#1989fa" style="top: 3px;"/> 标签数</van-col>
            </van-row>
            <van-row>
              <van-col span="12" class="list-value">{{item.fromWarehouseName}}</van-col>
              <van-col span="12" class="list-value">{{item.labelQty}}</van-col>
            </van-row>
            <van-row>
              <van-col span="12"><van-icon name="user-o" size="15" color="#1989fa" style="top: 3px;"/> 制单人</van-col>
              <van-col span="12"><van-icon name="friends-o" size="15" color="#1989fa" style="top: 3px;"/> 拣货人</van-col>
            </van-row>
            <van-row>
              <van-col span="12" class="list-value">{{item.busUser}}</van-col>
              <van-col span="12" class="list-value">{{item.picker}}</van-col>
            </van-row>
            <van-row>
              <van-col span="12"><van-icon name="sign" size="15" color="#1989fa" style="top: 3px;"/> 调拨类型</van-col>
              <van-col span="12"><van-icon name="sign" size="15" color="#1989fa" style="top: 3px;"/> 结算类型</van-col>
            </van-row>
            <van-row>
              <van-col span="12" class="list-value">{{formatBaseType(item.transferType)}}</van-col>
              <van-col span="12" class="list-value">{{cpMatrSettlementType(item.settlementType)}}</van-col>
            </van-row>
            <van-row v-show="cpShowReagent(item.transferType)">
              <van-col span="24">试剂组名称:{{item.reagentTeamName}}</van-col>
            </van-row>
            <van-row v-show="cpShowReagent(item.transferType)">
              <van-col span="24">试剂组地址:{{item.reagentTeamAddress}}</van-col>
            </van-row>
        </template>
      </FortenCollapse>
    </div>
    </van-form>
  </div>
</template>

<script>
import commonMixin from '@/util/mixin/commonMixin'

export default {
  data() {
    return {
      activeNames: [],
      scan: '',
      transferPickItems: [],
      reagentName: 'reagent'
    }
  },
  mixins: [commonMixin],
  props: {},
  created() {
    this.getTransferPickList()
  },
  mounted() {
    // let list = []
    // debugger
    // console.log(this.utils.getCurrentUser())
    // list.push(this.utils.getCurrentUser().name)
    // list.push(null)
    // list.push('')
    // let wrapper = this.$newWrapper().eq('flow_status', 'picking').in('picker', list)
    // const qString = JSON.stringify(wrapper.queryConditions)
    // const params = {
    //   queryString: qString,
    // }
    // const params = {flowStatus: 'picking'}
    // this.getTransferPickList(params)
  },
  computed: {
    cpMatrSettlementType() {
      return (settlementType) => {
        if (settlementType) {
          return this.utils.getDictLabel(settlementType, 'settlement_type', '用后结算', false)
        }
        return ''
      }
    },
    cpShowReagent() {
      return (transferType) => {
        return transferType == this.reagentName
      }
    }
  },
  methods: {
    //扫描
    handleScanOver(scanValue) {
      let hitOb = this.transferPickItems.find(ob => ob.busKey == scanValue)
      if (hitOb) {
        this.editPick(hitOb)
        // this.$notify.warning('未找到该调拨单')
        // window.scanError()
        return
      }
      this.scan = scanValue
      this.getTransferPickList(true)

      // const prefix =  this.scan.substring(0, 5)
      // if (prefix == 'trans') {
      //
      // } else {
      //   this.$notify.warning('调拨单号格式错误')
      // }
    },
    //获取所有数据
    getTransferPickList(isScan) {
      const { pid, toDetail } = this.$route.params
      const params = {
        busKey: this.scan,
        'isScan': isScan && isScan == true
      }
      this.$ajax.get('/wm/transfer/findAllListPDA', {params}).then(resp => {
        if (!(isScan && isScan == true)) this.transferPickItems = []
        this.resetScan()
        if (resp.code == 0 && resp.data) {
          if (isScan && isScan == true) {
            this.editPick(resp.data[0])
          } else {
            resp.data.forEach(o => this.transferPickItems.push(o))
            resp.data.forEach(o => this.activeNames.push(o.id))
            this.$refs.fsList.setData(this.transferPickItems)
          }
          if (toDetail) {
            this.$nextTick(() => {
              this.editPick(resp.data.find(d => d.id == pid))
            })
          }
        }
      })
    },
    resetScan() {
      this.scan = ''
      this.$refs.scanDom.focus()
    },
    editPick(transferPick) {
      //获取点击对象
      this.$router.push({
        name: 'editTransferPick',
        params: transferPick
      })
    },
    handleGoTo() {
      this.$router.push({name: 'tpItem'})
    },
    clearForm() {
      this.transferPickItems = []
      this.resetScan()
    },
    reload() {
      this.getTransferPickList()
    },

    //回调函数
    fsCall({item, type}) {

    }

  },
  components: {}

}
</script>

<style lang="scss" scoped>
  .items-container {
    min-height: 80px;
  }
</style>
